//
//  SelectPositionViewController.m
//  Leo01
//
//  Created by 张旭 on 15/9/21.
//  Copyright (c) 2015年 张旭. All rights reserved.
//

#import "SelectPositionViewController.h"

@interface SelectPositionViewController ()

@end

@implementation SelectPositionViewController
@synthesize cancelButton;
@synthesize confirmButton;
@synthesize pickerView;
@synthesize selectPosition;
@synthesize positionArray;
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setFrame:[UIScreen mainScreen].bounds];
    [self initDataArray];
    [self initButtonActions];
    pickerView.dataSource=self;
    pickerView.delegate=self;
    // Do any additional setup after loading the view from its nib.
}

-(void)initDataArray
{
    positionArray = [[NSMutableArray alloc]initWithObjects:@"学校",@"家", nil];
}

-(void)initButtonActions{
    [confirmButton addTarget:self action:@selector(submitAction) forControlEvents:UIControlEventTouchDown];
    [cancelButton addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchDown];
    UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)];
    [self.view addGestureRecognizer:tapGesture];

}
-(void)Actiondo:(id)sender
{
    if (selectPosition == nil) {
        selectPosition = @"";
    }
    self.motherLabel.text = [NSString stringWithFormat:@"%@", selectPosition];
    self.motherWindow.hidden=YES;
}

-(void)submitAction
{
    if (selectPosition == nil) {
        selectPosition = @"学校";
    }
    self.motherLabel.text = [NSString stringWithFormat:@"%@", selectPosition];
    self.motherWindow.hidden=YES;
    
}

-(void)cancelAction
{
    self.motherWindow.hidden=YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    if(self.view.window==nil)
    {
        self.view=nil;
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
//返回显示的列数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}
//返回当前列显示的行数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return positionArray.count;
    
}

//返回当前行的内容,此处是将数组中数值添加到滚动的那个显示栏上
-(NSString*)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [positionArray objectAtIndex:row];
    
}
// 当用户选中UIPickerViewDataSource中指定列和列表项时激发该方法
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    if(component == 0){
        selectPosition = [positionArray objectAtIndex:row];
    }
}

@end
